<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	<title>Login</title>
	<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
</head>
<body>
	<%@ include file="NavBar.jsp" %>
	<div class="container">
	<% try {
		
		if(request.getAttribute("login").equals("failed")) { %>
		<div class="alert alert-error"><strong>Login Failed: your login has failed</strong></div>
	<%  } 
	 	} catch (NullPointerException e) {
	 	}%>
	<h1>Login</h1>
	<form class="form-horizontal" method="post" action="Login">
 
	  <% 
      String emailStatus = null;
      try { 
    	  emailStatus = new String((String) request.getAttribute("emailStatus"));
    	  if(emailStatus.equals("noEmailInserted") || emailStatus.equals("wrongEmailInserted") || emailStatus.equals("notFound"))
	      {
    		  out.print("<div class=\"control-group error\">");
	      } else {
	    	  throw new NullPointerException ();
	      }
      }
      catch (NullPointerException e) {
    	  out.print("<div class=\"control-group\">");
      }
	  %>
	    <label class="control-label" for="inputEmail">Email</label>
	    <div class="controls">
	      <%
	      try { 
	    	  emailStatus = new String((String) request.getAttribute("emailStatus"));
	    	  if(emailStatus.equals("noEmailInserted"))
		      {
					out.print("<input type=\"text\" id=\"inputError\" name=\"inputEmail\" placeholder=\"Email\">");  	  
					out.print("<span class=\"help-inline\">No email insterted</span>");	
		      }	else if (emailStatus.equals("wrongEmailInserted")) {
					out.print("<input type=\"text\" id=\"inputError\" name=\"inputEmail\" placeholder=\"Email\">");  	  
					out.print("<span class=\"help-inline\">This is not a valid mail</span>");
		      } else if (emailStatus.equals("notFound")) {
					out.print("<input type=\"text\" id=\"inputError\" name=\"inputEmail\" placeholder=\"Email\">");  	  
					out.print("<span class=\"help-inline\">User not Found</span>");
		      } else {
		    	  throw new NullPointerException ();
		      }
	      }
	      catch (NullPointerException e) {
	    	  out.print("<input type=\"text\" id=\"inputEmail\" name=\"inputEmail\" placeholder=\"Email\"");  	      	  
		    	try {
		    		String email = (String) request.getAttribute("email");
		    		if (email.equals("null")) {
		    			throw new NullPointerException();
		    		} else
		    		{
			    		out.print(" value=\"" + email + "\">");
		    		}
		    	} catch (NullPointerException f) {
		    		out.print(">");  
		      	}
	      }
	      %>
	    </div>
	  </div>
	  
	<% 
      String passwordStatus = null;
      try { 
    	  passwordStatus = new String((String) request.getAttribute("passwordStatus"));
    	  if(passwordStatus.equals("wrongPassword") || passwordStatus.equals("noPasswordInserted"))
	      {
    		  out.print("<div class=\"control-group error\">");
	      } else {
	    	  throw new NullPointerException ();
	      }
      }
      catch (NullPointerException e) {
    	  out.print("<div class=\"control-group\">");
      }
	  %>
	    <label class="control-label" for="inputPassword">Password</label>
	    <div class="controls">
	      <%
	      try { 
	    	  passwordStatus = new String((String) request.getAttribute("passwordStatus"));
	    	  if(passwordStatus.equals("wrongPassword"))
		      {
		    	  out.print("<input type=\"password\" id=\"inputError\" name=\"inputPassword\" placeholder=\"Password\">");  	  
		    	  out.print("<span class=\"help-inline\">Password is wrong or user does not exist!</span>");	    	
		      }	else if (passwordStatus.equals("noPasswordInserted")) {
		    	  out.print("<input type=\"password\" id=\"inputError\" name=\"inputPassword\" placeholder=\"Password\">");  	  
		    	  out.print("<span class=\"help-inline\">You must specify a password!</span>");	    	
		      } else {
		    	  throw new NullPointerException ();
		      }
	      }
	      catch (NullPointerException e) {
	    	  out.print("<input type=\"password\" id=\"inputPassword\" name=\"inputPassword\" placeholder=\"Password\">");  	      	  
	      }
	      %>
	    </div>
	  </div>
	  
	  <div class="control-group">
	    <div class="controls">
	      <button type="submit" class="btn">Sign in</button>
	    </div>
	  </div>
	</form>
 </div>
</body>
</html>